@directive dynamic user;
@var content = {
<div class="panel panel-success">
    <div class="panel-body">
        <form class="form-horizontal" role="form" id="edit-form">
            <input type="hidden" name="id" id="id" value="${user.id}">
            <div class="form-group">
                <label class="col-sm-2 control-label">用户名</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="name" name="name"
                           placeholder="输入用户名" required data-bv-notempty-message="用户名不为空"
                           pattern="^.{2,10}$" data-bv-regexp-message="用户名在两到十个字符之间"
                           value="${user.name}" readonly/>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">昵称</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="code" name="code"
                           placeholder="输入昵称" required data-bv-notempty-message="昵称不为空"
                           pattern="^.{2,10}$" data-bv-regexp-message="昵称在两到十个字符之间"
                           value="${user.nick}" readonly/>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">主角色</label>
                <div class="col-sm-8">
                    <input class="form-control" id="represent" name="represent"
                              placeholder="输入主角色" required data-bv-notempty-message="主角色不为空"
                              pattern="^.{2,1000}$" data-bv-regexp-message="主角色在两到一千个字符之间"
                              readonly value="${user.roleName}"/>
                </div>
            </div>
        </form>
        <div id="userRolesTable"></div>
    </div>
    <div class="panel-footer">
        <div class="row">
            <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">

            </div>
            <div class="text-center col-xs-4 col-sm-4 col-md-4 col-lg-4">

            </div>
            <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4 text-right">
                <button class="btn btn-success" id="btn-edit" onclick="view.submit();">保存</button>
                <button class="btn btn-warning" id="btn-close" onclick="parent.table.bootstrapTableExtension('close');">
                    取消
                </button>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            view.init();
        });
        var view = {
            table: null,//表格对象
            dataUrl: '${ctxPath}/sys/userRoles/list/${user.id}',//数据加载地址
            saveUrl: '${ctxPath}/sys/userRoles/edit/${user.id}',//删除数据地址
            selectedData: null,//选中的数据
            id: 0,//操作数据的主键
            defaultColumns: function () {
                var that = this;
                //表头数据列
                return [
                    {
                        checkbox: true,
                        field: 'hasPermission',
                        formatter: function (value, row, index) {
                            return {checked: value};
                        }, align: 'center'
                    },
                    {field: 'name', title: '名称', align: 'center'},
                    {field: 'code', title: '代码', align: 'center'},
                    {
                        field: 'createTime', title: '创建时间', align: 'center', sortable: false,
                        formatter: function (arg) {
                            return arg.slice(0, 10) + " " + arg.slice(11, 20);
                        }
                    },
                    {
                        field: 'updateTime', title: '修改时间', align: 'center',
                        formatter: function (arg) {
                            return arg.slice(0, 10) + " " + arg.slice(11, 20);
                        }
                    },
                ];
            },
            init: function () {
                var that = this;
                that.table = $('#userRolesTable').bootstrapTableExtension({
                    type: 'table',
                    dataUrl: that.dataUrl,
                    columns: that.defaultColumns(),
                    isShowToolbar: false,
                    pagination: false,
                    search: false
                });
            },
            submit: function () {
                var obj = this.table.bootstrapTable('getSelections');
                console.log(obj);
                // if (obj.length < 1) {
                //     layer.msg('请至少勾选一项菜单', {icon: 2});
                //     return false;
                // }
                var roleIds = [];
                for (var i = 0; i < obj.length; i++) {
                    roleIds.push(obj[i].id);
                }
                console.log(roleIds);
                $('#btn-edit').attr('disabled', 'disabled');
                $.ajax({
                    url: view.saveUrl,
                    type: 'post',
                    dataType: 'json',
                    data: {
                        roleIds: roleIds
                    },
                    success: function (data) {
                        console.log(data);
                        if (data.status) {
                            layer.msg(data.msg, {icon: 1});
                            //wpgaci.goUrl('/sys/role/index', 1.5);
                            parent.table.bootstrapTable('refresh');
                            setTimeout(function () {
                                parent.table.bootstrapTableExtension('close');
                            }, 1500);
                        } else {
                            layer.msg(data.msg, {icon: 2});
                            $('#btn-edit').removeAttr('disabled');
                        }
                    },
                    error: function () {
                        layer.msg('网络错误，请稍后再试', {icon: 2});
                        $('#btn-edit').removeAttr('disabled');
                    }
                });
            }
        };
    </script>
</div>
@};
@include('../../layout/_open_content.html',{content:content}){}